import Vue from 'vue'
import App from './App.vue'
import router from './router'
import VueQuillEditor from 'vue-quill-editor'
import axios from 'axios'
import TreeTable from 'vue-table-with-tree-grid'

import './plugins/element.js'
// 导入全局样式
import './assets/css/global.css'
// 富文本编辑器
import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme
//导入进度条效果 nprogress
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'



Vue.prototype.$http = axios
//默认请求路径前缀
axios.defaults.baseURL = 'https://lianghj.top:8888/api/private/v1/'
// 设置请求头 带有token
axios.interceptors.request.use(config => {
  //在request中显示Nprogress 进度条
  NProgress.start();
  // Do something before request is sent
  config.headers.Authorization = window.sessionStorage.getItem('token')
return config;
},error => {
// Do something with request error
return Promise.reject(error);
});

//在response中隐藏Nprogress 进度条
axios.interceptors.response.use(config => {
  NProgress.done();
  return config;
})

//注册TreeTable 树形列表
Vue.component('tree-table', TreeTable)
//注册富文本编辑器到Vue中
Vue.use(VueQuillEditor)
Vue.config.productionTip = false

//日期格式过滤器
Vue.filter('dataFormat', function (originValue) {
  const dt = new Date(originValue)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')

  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')

  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
